package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.PictureMS;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface PictureMSMapper {
    @Delete({
        "delete from picture_m_s",
        "where pictureId = #{pictureid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer pictureid);

    /*通过UID删除*/
    @Delete({
            "delete from picture_m_s",
            "where postId = #{postId,jdbcType=INTEGER}"
    })
    int deleteByPostID(Integer postId);

    @Insert({
        "insert into picture_m_s (pictureId, pictureurl, ",
        "createtime, medicineId, ",
        "postId)",
        "values (#{pictureid,jdbcType=INTEGER}, #{pictureurl,jdbcType=VARCHAR}, ",
        "now(), #{medicineid,jdbcType=INTEGER}, ",
        "#{postid,jdbcType=INTEGER})"
    })
    int insert(PictureMS record);


    @Select({
        "select",
        "pictureId, pictureurl, createtime, medicineId, postId",
        "from picture_m_s",
        "where pictureId = #{pictureid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="pictureId", property="pictureid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="pictureurl", property="pictureurl", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="medicineId", property="medicineid", jdbcType=JdbcType.INTEGER),
        @Result(column="postId", property="postid", jdbcType=JdbcType.INTEGER)
    })
    PictureMS selectByPrimaryKey(Integer pictureid);

    @Select({
        "select",
        "pictureId, pictureurl, createtime, medicineId, postId",
        "from picture_m_s"
    })
    @Results({
        @Result(column="pictureId", property="pictureid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="pictureurl", property="pictureurl", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="medicineId", property="medicineid", jdbcType=JdbcType.INTEGER),
        @Result(column="postId", property="postid", jdbcType=JdbcType.INTEGER)
    })
    List<PictureMS> selectAll();

    /*通过medicineID查询*/
    @Select("select pictureurl from picture_m_s where medicineId=#{medicineId}")
    List<String> selectByMedicineId(@Param("medicineId")Integer medicineId);



    /*通过PostID删除图片*/
    @Delete("delete from picture_m_s where postId=#{postId}")
    int deleteByPostId(Integer postId);

    /*通过MedicineID删除图片*/
    @Delete("delete from picture_m_s where medicineId=#{medicineId}")
    int deleteByMedicineId(Integer medicineId);

    /*通过postID查询图片*/
    @Select("select pictureurl from picture_m_s where postId=#{postId}")
    List<String> selectByPostId(Integer postId);

    @Update({
        "update picture_m_s",
        "set pictureurl = #{pictureurl,jdbcType=VARCHAR},",
          "createtime = now(),",
          "medicineId = #{medicineid,jdbcType=INTEGER},",
          "postId = #{postid,jdbcType=INTEGER}",
        "where pictureId = #{pictureid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(PictureMS record);
}